home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / silo.lha / silo / Resource.h < prev    next >
C/C++ Source or Header  |  1993-08-08  |  1KB  |  46 lines

  1. /* $Author: ecsv38 $ $Date: 90/08/21 14:46:29 $ $Revision: 1.1 $ */
  2. /* (c) S. Manoharan  sam@lfcs.edinburgh.ac.uk */
  3.  
  4. #ifndef Resource_H
  5. #define Resource_H
  6.  
  7. //
  8. // An entity can reserve a resource for an event of type event_type.
  9. // Reserved or preempted resources can later be released. Reserve,
  10. // if unsuccessful, places the entity in blockedQ and returns 0.
  11. // A release examines the blockedQ for blocked entities, removes
  12. // the head of the Q and re-schedules the event during which the entity
  13. // got blocked.
  14. //
  15.  
  16. #include "Entity.h"
  17. #include "SimEntityList.h"
  18.  
  19. class Resource {
  20. private:
  21.    char *resource_name;
  22.    int available;
  23.    short resource_used;
  24.    SimEntityList blockedQ, servedQ;
  25. public:
  26.    Resource(const int = 1, char *const s = 0);
  27.    virtual ~Resource()    { }
  28.  
  29.    virtual void set(const int sz);
  30.    virtual short status()    { return available == 0; }
  31.  
  32.    virtual short reserve(Entity *const bywho, const int event_type);
  33.    virtual short preempt(Entity *const bywho, const int event_type);
  34.    virtual void release(Entity *const bywho);
  35. };
  36.  
  37. inline
  38. Resource::Resource(const int sz, char *const s)
  39. {
  40.    available = sz;
  41.    resource_name = s;
  42.    resource_used = 0;
  43. }
  44.  
  45. #endif Resource_H
  46.